package com.example.demo.utils;

import java.util.Objects;
import java.util.stream.Stream;

/**
 * 枚举工具类.
 *
 * @author Mei Ruoxiao
 * @since 2020/9/14
 */
public class EnumUtil {
    public EnumUtil() {
    }
    public static <T, R> T of(Class<T> clazz, final R value) {
        return Stream.of(clazz.getEnumConstants()).filter((t) -> {
            try {
                return Objects.equals(clazz.getDeclaredMethod("value").invoke(t), value);
            } catch (Exception e) {
                e.printStackTrace();
                return false;
            }
        }).findFirst().orElse(null);
    }
}
